home *** CD-ROM | disk | FTP | other *** search
- /*****************************************************************************/
- /* (C) 1993,1994 R. NADE - M. GRANDCHAMP - All Rights Reserved */
- /*****************************************************************************/
- /* This source-code is NOT public domain nor Freeware, this is part of */
- /* 'The C Programming Package' which is Shareware. */
- /* If you use this code, please register and get a free Full-VGA version */
- /*****************************************************************************/
- /*-----------------------*
- * CPPFIC4.C *
- * File Manager *
- * Display of selected *
- * file (CPPFIC1B) *
- * store in filedir. *
- *-----------------------*/
-
- /* Included Files */
- # include <stdio.h>
- # include <io.h>
- # include <dos.h>
- # include <fcntl.h>
- # include <bios.h>
- # include <stdlib.h>
- # include <conio.h>
- # include <dir.h>
- # include <string.h>
- # include <alloc.h>
- # include <mem.h>
- # include <sys\stat.h>
-
- /* Global Variables */
- extern int bm,i,j,k,l,m,n,t,x,xm,y,ym,z,menu0,menu1,return1,hexa,line;
- extern int colour1,colour2,colour3,colour4,colour5,nbdisk,return2,return3,recording;
- extern int lline,linemax,chx,choice,modif,pfdiv,pfserv,pfhelp,pfic,returning;
- extern unsigned int ref,nbref,nbrep;
- extern long dep,depdiv,dephelp,depbeginning,enddep,depfile;
- extern unsigned long nbbytes;
- extern char *memory,*diversity;
- extern unsigned char c0,c1,trashcan[],path[],nc1[],trashret[],filedir[];
- extern unsigned char work[],record[],saverep[];
- extern struct ffblk ffblk;
- extern struct directory{
- unsigned char name[9];
- unsigned char ext[4];
- unsigned char size[9];
- unsigned char attribut[2];
- unsigned char date[9];
- unsigned char time[6];
- } directory;
-
- /*------------------------------*
- * CLEAR SPACES (variable char) *
- *------------------------------*/
- void clear_spaces(varchar)
- unsigned char *varchar;
- {
- /* Cut spaces on the right of the word */
- i=strlen(varchar);
- for(j=(i-1); j>0; j--){
- if((varchar[j]==0x00)||(varchar[j]==0x20)) varchar[j]=0x00;
- else break;
- }
- /* Then, if required, on the left */
- i=strlen(varchar);
- for(j=0; j<i; j++) if(varchar[j]!=0x20) break;
- for(k=j; k<i; k++) trashret[k-j]=varchar[k];
- trashret[i-j]=0x00;
- }
- /*------------------------------*
- * DEFINE DISPLAY MODE *
- * Hexa or ASCII *
- * for the file to be displayed *
- *------------------------------*/
- void define_display_mode()
- {
- hexa=1;
- strcpy(trashcan,directory.ext); clear_spaces(trashcan);
- /* If there is no extension or not an extension usually used */
- /* to indicate a text file, we choose "a priori" */
- /* since it can be changed in the menu if it is not correct */
- if(strlen(trashcan)==0) hexa=0;
- if(strcmp(trashcan,"TXT")==0) hexa=0;
- if(strcmp(trashcan,"DOC")==0) hexa=0;
- if(strcmp(trashcan,"1ST")==0) hexa=0;
- if(strcmp(trashcan,"ME")==0) hexa=0;
- if(strcmp(trashcan,"ASC")==0) hexa=0;
- if(strcmp(trashcan,"MOI")==0) hexa=0;
- if(strcmp(trashcan,"PRG")==0) hexa=0;
- if(strcmp(trashcan,"C")==0) hexa=0;
- if(strcmp(trashcan,"PAS")==0) hexa=0;
- if(strcmp(trashcan," ")==0) hexa=0;
- }
- /*--------------------------------*
- * OPEN SELECTED FILE FOR READING *
- *--------------------------------*/
- int open_selected_file_for_reading()
- {
- if(pfic>0) close(pfic);
- pfic=open(filedir,O_RDONLY | O_BINARY,S_IREAD);
- if(pfic==-1){
- warning(" Cannot open"," the selected file ",""," Click the mouse"," or press any key");
- return(0);
- }
- enddep=lseek(pfic,0L,SEEK_END); depfile=lseek(pfic,0L,SEEK_SET);
- depbeginning=depfile; lseek(pfic,depfile,0);
- return(1);
- }
- /*------------------------------*
- * DISPLAY BORDER FOR HEXA FILE *
- *------------------------------*/
- void display_border_hexa_file()
- {
- /* Display in hexa with ASCII translation if possible */
- textattr(colour3);
- gotoxy(22,3); cputs("╔══════════╤════════════════════════╤════════╗");
- gotoxy(22,4); cputs("║ Offset │ Hexadecimal Text │ Text ║");
- gotoxy(22,5); cputs("╟──────────┼────────────────────────┼────────╢");
- for(i=6; i<24; i++){
- gotoxy(22,i); cputs("║ │ │ ║");
- }
- gotoxy(22,24); cputs("╩══════════╧════════════════════════╧════════╝");
- }
- /*----------------------------*
- * DISPLAY HEXA FILE - 1 PAGE *
- *----------------------------*/
- void display_hexa_file()
- {
- /* Display the border and erase the old one if required */
- display_border_hexa_file();
- for(line=6; line<24; line++){
- /* Display the offset from the beginning of the file */
- ltoa(depfile,nc1,10); clear_spaces(nc1);
- strcpy(trashcan,trashret);
- put_separators(); m=strlen(trashcan);
- gotoxy((32-m),line); cputs(trashcan);
- trashcan[8]=0x00;
- /* Then the text itself, if printable */
- if(depfile>(enddep-8)){
- /* This is the end of the file */
- k=enddep-depfile; trashcan[k]=0x00;
- lseek(pfic,depfile,0); read(pfic,trashcan,k);
- for(i=0; i<k; i++){
- j=trashcan[i]; itoa(j,nc1,16);
- if(j<0x10){
- nc1[1]=nc1[0]; nc1[0]=0x30;
- }
- nc1[2]=0x00;
- gotoxy((3*i+34),line); cputs(nc1);
- }
- for(j=0; j<k; j++){
- /* Cut all the control chars */
- if(trashcan[j]<0x21) trashcan[j]=0xfa;
- }
- gotoxy(59,line); cputs(trashcan);
- break;
- }
- /* Else read the whole line */
- lseek(pfic,depfile,0); read(pfic,trashcan,8);
- /* Display hexa as is */
- for(i=0; i<8; i++){
- j=trashcan[i]; itoa(j,nc1,16);
- if(j<0x10){
- nc1[1]=nc1[0]; nc1[0]=0x30;
- }
- nc1[2]=0x00;
- gotoxy((3*i+34),line); cputs(nc1);
- }
- for(j=0; j<8; j++){
- /* Treat every line but cut all the control chars */
- if(trashcan[j]<0x21) trashcan[j]=0xfa;
- }
- /* Then display the line */
- gotoxy(59,line); cputs(trashcan);
- /* And then go to the next line */
- depfile+=8;
- if(depfile>=enddep){
- /* This is the end of the file */
- sound1(); break;
- }
- }
- }
- /*---------------------------*
- * DISPLAY BORDER ASCII FILE *
- *---------------------------*/
- void display_border_ascii_file()
- {
- /* displayed in ASCII if possible */
- textattr(colour3);
- gotoxy(22,3); cputs("╔══════════╤═════════════════════════════════╗");
- gotoxy(22,4); cputs("║ Offset │ ASCII text (if printable) ║");
- gotoxy(22,5); cputs("╟──────────┼─────────────────────────────────╢");
- for(i=6; i<24; i++){
- gotoxy(22,i); cputs("║ │ ║");
- }
- gotoxy(22,24); cputs("╩══════════╧═════════════════════════════════╝");
- }
- /*--------------------*
- * DISPLAY ASCII PAGE *
- *--------------------*/
- void display_ascii_page()
- {
- /* Display the border and erase the old one if required*/
- display_border_ascii_file();
- for(line=6; line<24; line++){
- /* Display the offset from the beginning of the file */
- ltoa(depfile,nc1,10); clear_spaces(nc1);
- strcpy(trashcan,trashret);
- put_separators(); m=strlen(trashcan);
- gotoxy((32-m),line); cputs(trashcan);
- trashcan[32]=0x00;
- /* Then the text itself if printable */
- if(depfile>(enddep-32)){
- /* This is the end of the file */
- k=enddep-depfile; trashcan[k]=0x00;
- lseek(pfic,depfile,0); read(pfic,trashcan,k);
- for(j=0; j<32; j++){
- /* Cut all the control chars */
- if(trashcan[j]<0x21) trashcan[j]=0xfa;
- }
- gotoxy(35,line); cputs(trashcan);
- break;
- }
- /* Else read the full line */
- lseek(pfic,depfile,0); read(pfic,trashcan,32);
- for(j=0; j<32; j++){
- /* Treat every line but cut all the control chars */
- if(trashcan[j]<0x21) trashcan[j]=0xfa;
- }
- /* Then display the line */
- gotoxy(35,line); cputs(trashcan);
- /* Then go to next line */
- depfile+=32;
- if(depfile>=enddep){
- /* End of the file */
- sound1(); break;
- }
- }
- }
- /*----------------------------------*
- * DISPLAY SELECTED FILE MENU *
- *----------------------------------*/
- void display_selected_file_menu(value)
- int value;
- {
- hide_the_mouse(); textattr(colour3);
- /* Display the modifying part of the menu */
- gotoxy(69,10); cputs("║Beg. File ║");
- gotoxy(69,11); cputs("║Prev. page║");
- gotoxy(69,12); cputs("║Next page ║");
- gotoxy(69,13); cputs("║End file ║");
- gotoxy(69,14); cputs("║disp. Asci║");
- gotoxy(69,15); cputs("║disp. Hexa║");
- /* Overline the key letters */
- textattr(116);
- gotoxy(70,10); cputs("B");
- gotoxy(70,11); cputs("P");
- gotoxy(70,12); cputs("N");
- gotoxy(70,13); cputs("E");
- gotoxy(76,14); cputs("A");
- gotoxy(76,15); cputs("H");
- gotoxy(71,17); cputs("Q");
- /* Inverse the selected line */
- textattr(colour5);
- if(value==1){
- gotoxy(70,10); cputs("Beg. file ");
- }
- if(value==2){
- gotoxy(70,11); cputs("Prev. page");
- }
- if(value==3){
- gotoxy(70,12); cputs("Next page ");
- }
- if(value==4){
- gotoxy(70,13); cputs("End file ");
- }
- if(hexa==0){
- gotoxy(70,14); cputs("disp. Asci");
- }
- if(hexa==1){
- gotoxy(70,15); cputs("disp. Hexa");
- }
- show_the_mouse();
- }
- /*---------------------*
- * DISPLAY FILE BORDER *
- *---------------------*/
- void display_file_border()
- {
- hide_the_mouse(); textattr(colour1);
- gotoxy(69,5); cputs(" ");
- textattr(colour3);
- /* Erase what we do not need */
- window(22,3,67,24); clrscr();
- window(69,6,80,24); clrscr();
- window(1,18,22,24); clrscr();
- window(1,1,80,25);
- /* Get files info. */
- gotoxy(1,18); cputs("╔════════════════════╣");
- gotoxy(1,19); cputs("║Drive = ");
- gotoxy(1,20); cputs("║Files = ");
- gotoxy(1,21); cputs("║Size = Byt.");
- gotoxy(1,22); cputs("║Date = ");
- gotoxy(1,23); cputs("║Time = ");
- gotoxy(1,24); cputs("╚════════════════════");
- memcpy(trashcan,filedir,3); trashcan[3]=0x00;
- gotoxy(18,19); cputs(trashcan);
- strcpy(trashcan,directory.name); clear_spaces(trashcan);
- strcpy(trashcan,trashret);
- strcat(trashcan,"."); strcat(trashcan,directory.ext);
- clear_spaces(trashcan); i=strlen(trashret);
- gotoxy((21-i),20); cputs(trashret);
- strcpy(trashcan,directory.size); clear_spaces(trashcan);
- strcpy(trashcan,trashret);
- put_separators(); i=strlen(trashcan);
- gotoxy((17-i),21); cputs(trashcan);
- strcpy(trashcan,directory.date); clear_spaces(trashcan);
- gotoxy(13,22); cputs(trashret);
- strcpy(trashcan,directory.time); clear_spaces(trashcan);
- gotoxy(16,23); cputs(trashret);
- /* Draw the menu for the files search */
- gotoxy(69,6); cputs("╔══════════╗");
- gotoxy(69,7); cputs("║ M E N U ║");
- gotoxy(69,8); cputs("╚══════════╝");
- gotoxy(69,9); cputs("╔══════════╗");
- gotoxy(69,16); cputs("╟──────────╢");
- gotoxy(69,17); cputs("║ Quit ║");
- gotoxy(69,18); cputs("╚══════════╝");
- display_selected_file_menu(1);
- show_the_mouse();
- }
- /*----------------------------------*
- * GET_MOUSE_SELECTED_FILES_MANAGER *
- *----------------------------------*/
- int get_mouse_selected_files_manager()
- {
- if((xm>68)&&(xm<80)){
- if(ym==10){
- chx=1; return(1);
- }
- if(ym==11){
- chx=2; return(1);
- }
- if(ym==12){
- chx=3; return(1);
- }
- if(ym==13){
- chx=4; return(1);
- }
- if(ym==14){
- hexa=0; return(2);
- }
- if(ym==15){
- hexa=1; return(2);
- }
- if(ym==17){
- chx=7; return(-1);
- }
- }
- return(0);
- }
- /*--------------------------------*
- * DISPLAY SELECTED FILES MANAGER *
- *--------------------------------*/
- int display_selected_files_manager()
- {
- t=wait_for_a_key();
- /* If we pressed <Esc> <Q> <q> we go back to the menu */
- if((t==-1)||(t==26)) return(-1);
- if((t==13)||(t==71)){
- /* Beginning of the file */
- chx=1; return(1);
- }
- if((t==25)||(t==72)||(t==73)||(t==75)){
- /* Previous page */
- chx=2; return(1);
- }
- if((t==23)||(t==80)||(t==81)||(t==77)){
- /* Next page */
- chx=3; return(1);
- }
- if((t==14)||(t==79)){
- /* End of the file */
- chx=4; return(1);
- }
- if(t==10){
- /* Display in ASCII */
- hexa=0; return(2);
- }
- if(t==17){
- /* Display in Hexa */
- hexa=1; return(2);
- }
- if(t==59){
- /* <F1> = Help */
- return(59);
- }
- if(t==100){
- /* We used the mouse */
- t=get_mouse_selected_files_manager();
- return(t);
- }
- /* If we choosed something else or if we clicked */
- /* outside of the defined zone, nothing happens */
- return(0);
- }
- /*----------------------------*
- * DISPLAY SELECTED FILE *
- * the full name is in filedir *
- *----------------------------*/
- void display_selected_file()
- {
- /* Open the file in read only mode */
- returning=open_selected_file_for_reading();
- if(returning<1) return;
- define_display_mode(); display_file_border();
- while(1){
- if(hexa==0) display_ascii_page();
- else display_hexa_file();
- return3=display_selected_files_manager();
- if(return3==-1) break;
- if(return3==59){
- /* On-line Help */
- display_help("FILES",9,6,1); restore_help_screen();
- }
- if(return3==1){
- display_selected_file_menu(chx);
- if(chx==1){
- /* Beginning of the file */
- depfile=depbeginning; sound1();
- }
- if(chx==2){
- /* previous page of the file */
- /* We need to go up twice in the file */
- /* once for the displayed page, */
- /* once for the previous page */
- if(hexa==0){
- /* ASCII */
- depfile-=1152;
- if(depfile<=depbeginning){
- /* beginning of the file */
- depfile=depbeginning; sound1();
- }
- }
- else{
- /* hexadecimal */
- depfile-=288;
- if(depfile<=depbeginning){
- /* Beginning of the file */
- depfile=depbeginning; sound1();
- }
- }
- }
- if(chx==3){
- /* Next page of the file */
- /* We let the file reading going on */
- }
- if(chx==4){
- /* End of the file */
- if(hexa==0){
- /* ASCII */
- depfile=enddep-576; sound1();
- if(depfile<=depbeginning){
- /* beginning of the file */
- depfile=depbeginning; sound1();
- }
- }
- else{
- /* hexadecimal */
- depfile=enddep-144; sound1();
- if(depfile<=depbeginning){
- /* Beginning of the file */
- depfile=depbeginning; sound1();
- }
- }
- }
- if(chx==7){
- /* Quit */
- break;
- }
- }
- if(return3==2){
- display_selected_file_menu(chx);
- if(hexa==0){
- /* display in ASCII */
- /* First we go to the beginning of the page */
- depfile-=144;
- if(depfile<=depbeginning){
- /* Beginning of the file */
- depfile=depbeginning; sound1();
- }
- if(depfile>(enddep-576)){
- depfile=enddep-576; sound1();
- if(depfile<=depbeginning){
- /* Beginning of the file */
- depfile=depbeginning; sound1();
- }
- }
- }
- if(hexa==1){
- /* display in Hexa */
- /* We go to the beginning of the page */
- depfile-=576;
- if(depfile<=depbeginning){
- /* Beginning of the file */
- depfile=depbeginning; sound1();
- }
- if(depfile>(enddep-128)){
- depfile=enddep-128; sound1();
- if(depfile<=depbeginning){
- /* Beginning of the file */
- depfile=depbeginning; sound1();
- }
- }
- }
- }
- }
- close(pfic); pfic=0;
- /* Previous screen */
- display_directories_listing();
- diversity=memory; calculate_and_display_sum_of_files();
- memory=diversity; display_directory_files();
- display_drive_choice();
- display_menu_file_manager(choice);
- }
- /* End of the Module *//*-------------------*/
-
-
-